package fr.uniscol.dao.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import fr.uniscol.dao.IGeographieDao;
import fr.uniscol.dao.impl.GeographieDaoImpl;
import fr.uniscol.model.Departement;

public class DepartementRowMapper implements RowMapper<Departement> {

	private IGeographieDao geoDao;
	
	public DepartementRowMapper(IGeographieDao geoDao){
		this.geoDao = geoDao;
	}
	
	@Override
	public Departement mapRow(ResultSet rs, int line) throws SQLException {
		
		Departement dp = new Departement();
		dp.setId(rs.getInt("ID"));
		dp.setLibelleLong(rs.getString("NOM"));
		dp.setCodeMEN(rs.getString("CODE_MEN"));
		dp.setCodeInsee(rs.getString("CODE_INSEE"));
		
		if(rs.getString("ACADEMIEID") != null){
			dp.setAcademie(geoDao.getAcademieById(rs.getInt("ACADEMIEID")));
		}
		
		return dp;
	}
}
